#ifndef FRAMEPROVIDER_H
#define FRAMEPROVIDER_H

#include <QObject>
#include <QAbstractVideoSurface>
#include <QVideoSurfaceFormat>

// qml渲染yuv，qt官方推荐做法
// https://doc.qt.io/qt-5/videooverview.html

// 基本原理是把我们的自定义类FrameProvider的实例，赋值给VideoOutput的source属性
// 这样VideoOutput就会通过FrameProvider的setVideoSurface接口把它的QAbstractVideoSurface设置给FrameProvider
// 然后我们就可以在FrameProvider中通过m_surface->present(frame)把视频帧提供给VideoOutput渲染了

class FrameProvider : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QAbstractVideoSurface *videoSurface READ videoSurface WRITE setVideoSurface)


public:
    QAbstractVideoSurface* videoSurface() const { return m_surface; }

private:
    QAbstractVideoSurface *m_surface = NULL;
    QVideoSurfaceFormat m_format;

public:
    void setVideoSurface(QAbstractVideoSurface *surface);

    void setFormat(int width, int heigth, int format);

public slots:
    void onNewVideoContentReceived(const QVideoFrame &frame);
};

#endif // FRAMEPROVIDER_H
